package util;

import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class DFormat {

	public DFormat() {
		
	}
	
	public static String format(Object value, int nDec) {
		String pattern = "###,##0.";
		int d; 
		
		for (d = 0; d < nDec; d ++) pattern += "0";
		
		DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
		simbolos.setDecimalSeparator('.');
		simbolos.setGroupingSeparator(',');
		DecimalFormat nf = new DecimalFormat(pattern, simbolos);
		
		return nf.format(value);
	}
	
	public static String cformat(Object value, int nDec) {
		String pattern = "##0.";
		int d; 
		
		for (d = 0; d < nDec; d ++) pattern += "0";
		
		DecimalFormatSymbols simbolos = new DecimalFormatSymbols();
		simbolos.setDecimalSeparator('.');
		
		DecimalFormat nf = new DecimalFormat(pattern, simbolos);
		
		return nf.format(value);
	}
}
